package com.atguigu.com.nio.nio_2_channel;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * @Author: robert.song
 * @Date: Created in 2021/8/7
 */
public class NIOFileChannel04 {
    public static void main(String[] args) throws IOException {
//        transferFrom() 从目标通道复制到当前通道
//        创建流
        FileInputStream fileInputStream = new FileInputStream("D:\\file\\project\\cx\\test.log");
        FileOutputStream fileOutpustStream = new FileOutputStream("D:\\file\\project\\cx\\test-copy-by-transferForm.log");
//        获取channel
        FileChannel sourceCh = fileInputStream.getChannel();
        FileChannel destCh = fileOutpustStream.getChannel();
//        使用transferForm完成拷贝
        destCh.transferFrom(sourceCh, 0, sourceCh.size());
//        关闭通道和流
        fileInputStream.close();
        fileOutpustStream.close();
    }
}
